<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>新增会议室信息</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../../../static/css/select.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../../static/js/jquery.js"></script>
    <script type="text/javascript" src="../../../static/js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="../../../static/js/select-ui.min.js"></script>
    <script type="text/javascript" src="../../../static/editor/kindeditor.js"></script>

    <script type="text/javascript" src="../../../static/js/vue.js"></script>
    <script type="text/javascript" src="../../../static/js/axios.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });

        });
    </script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".click").click(function(){
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function(){
                $(".tip").fadeOut(200);
            });
            $(".sure").click(function(){
                $(".tip").fadeOut(100);
                vm.toAdd();
            });

            $(".cancel").click(function(){
                $(".tip").fadeOut(100);
            });

        });
    </script>
</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">会议管理</a></li>
        <li><a href="#">会议管理</a></li>
    </ul>
</div>

<div class="formbody" id="addRoom">

    <div class="formtitle"><span>基本信息</span></div>
    <ul class="forminfo">
        <li>
            <label>会议室名: </label>
            <input type="text" class="scinput"  id="meetRoomName" @blur="testMeetRoomName()" />
            <i id="meetRoomNameHint"></i>
        </li>
        <li>
            <label>会议室地址: </label>
            <input type="text" class="scinput"  id="meetRoomPlace" @blur="testMeetRoomPlace()" />
            <i id="meetRoomPlaceHint"></i>
        </li>
        <li>
            <label>容量: </label>
            <input type="text" class="scinput"  id="capacity" @blur="testCapacity()" />
            <i id="capacityHint"></i>
        </li>
        <li>
            <label>是否有空调: </label>
            <input type="radio" name="isHaveHvac" checked  value="0"/>无
            <input type="radio" name="isHaveHvac"  value="1"/>有
        </li>

        <li>
            <label>&nbsp;</label>
            <input type="button" value="返回" class="btn" onclick="window.history.go(-1);"/>
            <input type="button" class="btn click" value="确认"/>
        </li>
    </ul>
    <!--<table class="tablelist">
        <thead>
            <tr>
                <th>会议号</th>
                <th>预约部门</th>
                <th>会议开始时间</th>
                <th>会议结束时间</th>
                <th>预约人</th>
                <th>会议状态</th>
            </tr>
        </thead>
        <tbody>
            <tr v-for=" reservationmeetroom in messages.reservationmeetroomList ">
                <td>{{reservationmeetroom.rid}}</td>
                <td>{{reservationmeetroom.dept.deptName}}</td>
                <td>{{reservationmeetroom.meetstarttime}}</td>
                <td>{{reservationmeetroom.meetendtime}}</td>
                <td>{{reservationmeetroom.reservationUser==null?'':reservationmeetroom.reservationUser.empName}}</td>
                <td v-if="reservationmeetroom.status ==0">未失效</td>
                <td v-if="reservationmeetroom.status ==1">失效</td>
            </tr>
        </tbody>
    </table>-->
    <div class="tip">
        <div class="tiptop"><span>提示信息</span>
            <a></a>
        </div>

        <div class="tipinfo">
            <span><img src="../../../static/images/ticon.png" /></span>
            <div class="tipright">
                <p>是否确认对信息的添加 ？</p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
            </div>
        </div>

        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定" />&nbsp;
            <input name="" type="button" class="cancel" value="取消" />
        </div>

    </div>
</div>

    <script type="text/javascript">

        //用户信息
        var customOneName = JSON.parse(sessionStorage.getItem("customer"));

        var flag1 = false;
        var flag2 = false;

        var vm = new Vue({
            el:"#addRoom",
            methods:{
                toAdd(){
                    var meetRoomName = $('#meetRoomName').val();
                    var meetRoomPlace = $('#meetRoomPlace').val();
                    var capacity = $('#capacity').val();
                    var isHaveHvac = $("[name='isHaveHvac']").val();

                    if(this.testCapacity()  & this.testMeetRoomPlace()  & this.testMeetRoomName()  ){
                        axios({
                            method:'post',
                            url:'/meetroom/add',
                            data:{
                                // "createUserId":1,   //登录人id
                                "createUserId":customOneName.id,   //登录人id
                                "meetRoomName":meetRoomName,
                                "meetRoomPlace":meetRoomPlace,
                                "capacity":Number.parseInt(capacity),
                                "isHaveHvac":Number.parseInt(isHaveHvac),
                            }
                        }).then(function(res){
                            alert("添加成功!!!");
                            window.history.go(-1);
                        }).catch(function (reason) {
                            alert("添加失败!!!");
                        })
                    }

                },
                testMeetRoomName:function (){
                    var meetRoomName = $('#meetRoomName').val();
                    if(this.isEmpty(meetRoomName) == 1){
                        $("#meetRoomNameHint").text("会议室名不能为空！！！");
                        flag1 = false;
                    }else{
                        axios({
                            method:'post',
                            url:'/meetroom/testMeetRoomName/'+meetRoomName,
                        }).then(function(res){
                            if(res.data == false){
                                $('#meetRoomName').val("");
                                $("#meetRoomNameHint").text("会议室名称重复,请重新输入！！！");
                                flag1 =  false;
                            }else {
                                flag1 = true;
                                $("#meetRoomNameHint").text("");
                            }

                        }).catch(function (reason) {
                            alert("返回失败!!!");
                        })
                    }
                    return flag1;
                },
                testMeetRoomPlace:function (){
                    var meetRoomPlace = $('#meetRoomPlace').val();
                    if(this.isEmpty(meetRoomPlace) == 1){
                        $("#meetRoomPlaceHint").text("会议室地址不能为空！！！");
                        flag2 = false;
                    }else{
                        axios({
                            method:'post',
                            url:'/meetroom/testMeetRoomPlace/'+meetRoomPlace,
                        }).then(function(res){
                            if(res.data == false){
                                $('#meetRoomPlace').val("");
                                $("#meetRoomPlaceHint").text("会议室地址重复,请重新输入！！！");
                                flag2 =  false;
                            }else {
                                flag2 = true;
                                $("#meetRoomPlaceHint").text("");
                            }

                        }).catch(function (reason) {
                            alert("返回失败!!!");
                        })
                    }
                    return flag2;
                },
                testCapacity:function (){
                    var capacity = $('#capacity').val();
                    if(this.isEmpty(capacity)){
                        $("#capacityHint").text("容量不能为空！！！");
                        return false;
                    }else if( !this.isNum(capacity)){
                        $('#capacity').val("");
                        $("#capacityHint").text("请重新输入，容量为数字类型！！！");
                        return false;
                    }else {
                        return true;
                    }
                },
                isEmpty:function (ele) {
                    if(ele == null || ele ==''){
                        return 1;
                    }
                    return 0;
                },
                isNum:function (ele) {
                    var numReg = /^[0-9]*$/;
                    return numReg.test(ele);
                }
            },
            //页面加载完自动执行
            mounted(){
            }
        });
    </script>
</body>

</html>